<template>
  <div>
    <el-card shadow="always">
      <el-row type="flex" :gutter="20" align="middle">
        <el-col :span="4">
          <el-cascader
            :options="optionsArea"
            :props="{
              value: 'areaCode',
              label: 'areaName',
              children: 'children',
              checkStrictly: true,
            }"
            ref="cascader"
            @change="CascaderArea"
            :show-all-levels="false"
            v-model="query.areaCode"
          ></el-cascader>
        </el-col>
        <!-- <el-col :span="4">
          <el-cascader
            clearable
            placeholder="请选择单位业态"
            v-model="bodyindustryStr"
            :options="bodyindustryList"
            @change="onCascaderChange"
            :collapse-tags="true"
            :props="{
              checkStrictly: true,
              multiple: true,
            }"
          ></el-cascader>
        </el-col> -->
        <el-col :span="4">
          <el-select
            v-model="query.chiefInspector"
            clearable
            collapse-tags
            multiple
            placeholder="请选择单位类型"
          >
            <el-option
              :label="item.label"
              :value="item.value"
              v-for="item in [
                {
                  label: '未设置',
                  value: '未设置',
                },

                {
                  label: '大型餐饮服务企业',
                  value: '大型餐饮服务企业',
                },
                {
                  label: '中型餐饮服务企业',
                  value: '中型餐饮服务企业',
                },
                {
                  label: '大型食品销售企业',
                  value: '大型食品销售企业',
                },
                {
                  label: '中型食品销售企业',
                  value: '中型食品销售企业',
                },
                {
                  label: '托幼机构食堂(用餐人数300以上)',
                  value: '托幼机构食堂(用餐人数300以上)',
                },
                {
                  label: '学校食堂(用餐人数500以上)',
                  value: '学校食堂(用餐人数500以上)',
                },

                {
                  label: '其他学校食堂（含托幼机构，需总监）',
                  value: '其他学校食堂（含托幼机构，需总监）',
                },
                {
                  label: '用餐（供餐）1000人以上的单位',
                  value: '用餐（供餐）1000人以上的单位',
                },
                {
                  label: '食用农产品批发市场',
                  value: '食用农产品批发市场',
                },
                {
                  label: '网络平台（需设置总监）',
                  value: '网络平台（需设置总监）',
                },

                {
                  label: '其他企业(无需设置总监)',
                  value: '其他企业(无需设置总监)',
                },
                {
                  label: '其他企业(无需设置总监)(仅限市平台单位)',
                  value: '其他企业(无需设置总监)(仅限市平台单位)',
                },
              ]"
              :key="item.value"
            ></el-option>
          </el-select>
        </el-col>
        <el-col :span="4">
          <el-input
            clearable
            maxlength="50"
            v-model="query.identify"
            placeholder="请输入统一社会信用代码"
          ></el-input>
        </el-col>
        <el-col :span="4">
          <el-input
            maxlength="50"
            clearable
            v-model="query.newlicenseno"
            placeholder="请输入许可证编号"
          ></el-input>
        </el-col>
        <el-col :span="4">
          <el-input
            clearable
            maxlength="50"
            v-model="query.unitname"
            placeholder="请输入单位名称"
          ></el-input>
        </el-col>
        <el-col :span="2">
          <el-button
            type="primary"
            @click="
              getList();
              query.page = 1;
            "
            >查询</el-button
          ></el-col
        >
        <el-col :span="2">
          <el-button type="default" @click="getPilotExport">导出</el-button></el-col
        >
      </el-row>
      <rz-height></rz-height>

      <el-row>
        <el-col :span="24">
          <el-table border :data="tableData" style="width: 100%" stripe>
            <el-table-column label="区域街道" prop="districtName" width="180">
              <template slot-scope="scope">
                <div>{{ scope.row.districtName }}--{{ scope.row.streetName }}</div>
              </template>
            </el-table-column>

            <el-table-column label="单位名称" prop="operatorName" width="380">
              <template slot-scope="scope">
                <div>
                  {{ scope.row.operatorName || scope.row.unitName }}
                </div>
              </template>
            </el-table-column>
            <!-- <el-table-column label="单位业态" width="200" prop="bodyindustry">
              <template slot-scope="scope">
                <div>
                  {{ scope.row.bodyIndustry
                  }}{{
                    scope.row.bodyIndustryRemarks
                      ? "--" + scope.row.bodyIndustryRemarks
                      : ""
                  }}
                </div>
              </template>
            </el-table-column>

   <el-table-column label="单位类型" width="200" prop="remark"></el-table-column> -->

            <!-- <el-table-column
              width="180"
              label="统一社会信用代码"
              prop="identify"
            ></el-table-column> -->
            <el-table-column label="许可证编号" width="150" prop="newLicenseNo">
              <template slot-scope="scope">
                <div>{{ scope.row.newLicenseNo || "--" }}</div></template
              ></el-table-column
            >

            <el-table-column label="联系人" width="200" prop="newLicenseNo">
              <template slot-scope="scope">
                <div>
                  {{ scope.row.contactor || "--"
                  }}{{ scope.row.contactTelStr ? "(" + scope.row.contactTel + ")" : "" }}
                </div></template
              ></el-table-column
            >

            <el-table-column label="经营地址" prop="productionAddress"></el-table-column>
          </el-table>
          <pagination
            :total="total"
            :page.sync="query.page"
            @pagination="getList"
            v-show="total"
          />
        </el-col>
      </el-row>
    </el-card>
    <!-- <rz-dialog
      :dialogVisible.sync="dialogVisible"
      :isShowConfirm="false"
      :title="title"
    >
      <inspect
        :classification="classification"
        :taskStatus="taskStatus"
        :unId="unId"
        v-if="dialogVisible"
        :clearable="true"
      ></inspect>
    </rz-dialog> -->

    <rz-dialog
      :dialogVisible.sync="dialogVisibleLabel"
      title="编辑单位标签"
      width="70%"
      @onconfirm="onconfirm"
    >
      <el-form ref="form" :model="sendData" label-width="160px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="单位名称">
              {{ sendData.unitName }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="统一社会信用代码">
              {{ sendData.identify }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="单位业态">
              {{ sendData.bodyIndustry
              }}{{
                sendData.bodyIndustryRemarks
                  ? "--" + sendData.bodyIndustryRemarks
                  : sendData.bodyIndustryRemarks
              }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="许可证编号">
              {{ sendData.newLicenseNo || "--" }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="单位类型">
              <el-select v-model="sendData.remark" clearable placeholder="请选择单位类型">
                <el-option
                  :label="item.label"
                  :value="item.value"
                  v-for="item in [
                    {
                      label: '大型餐饮服务企业',
                      value: '大型餐饮服务企业',
                    },
                    {
                      label: '中型餐饮服务企业',
                      value: '中型餐饮服务企业',
                    },
                    {
                      label: '大型食品销售企业',
                      value: '大型食品销售企业',
                    },
                    {
                      label: '中型食品销售企业',
                      value: '中型食品销售企业',
                    },
                    {
                      label: '托幼机构食堂(用餐人数300以上)',
                      value: '托幼机构食堂(用餐人数300以上)',
                    },
                    {
                      label: '学校食堂(用餐人数500以上)',
                      value: '学校食堂(用餐人数500以上)',
                    },

                    {
                      label: '其他学校食堂（含托幼机构，需总监）',
                      value: '其他学校食堂（含托幼机构，需总监）',
                    },

                    {
                      label: '用餐（供餐）1000人以上的单位',
                      value: '用餐（供餐）1000人以上的单位',
                    },
                    {
                      label: '食用农产品批发市场',
                      value: '食用农产品批发市场',
                    },
                    {
                      label: '网络平台（需设置总监）',
                      value: '网络平台（需设置总监）',
                    },

                    {
                      label: '其他企业(无需设置总监)',
                      value: '其他企业(无需设置总监)',
                    },
                    {
                      label: '其他企业(无需设置总监)(仅限市平台单位)',
                      value: '其他企业(无需设置总监)(仅限市平台单位)',
                    },
                  ]"
                  :key="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </rz-dialog>
  </div>
</template>
<script>
import { groupArea } from "@/api/modules/enterprise";
// import { exportGroupMealPilot } from "@/api/modules/coldLink";
// import { saveSuperViseUnitLabel } from "@/api/modules/enterprise";
import { findSuperViseUnitDealtList } from "@/api/modules/enterprise";
import {
  saveDealtSuperViseUnitLabel,
  exportSuperViseUnitDeal,
  findSysDicBusiness
} from "@/api/modules/enterprise";
export default {
  name: "archives",
  components: {},
  created() {
    if (this.$route.query.code) {
      this.query.areaCode = this.$route.query.code;
    } else {
      this.query.areaCode = "320500000000";
    }
    // this.query.startDateCompletion = this.$moment().format("YYYY-MM-DD");
    // this.query.endDateCompletion = this.$moment().format("YYYY-MM-DD");
    this.getList();
    // this.findUnitBodyIndustryLink();
    this.findAreaListNoParentByParentCode();
    // this.unitLabel();
  },
  mounted() {},
  data() {
    return {
      dialogVisible: false,
      dialogVisibleLabel: false,
      tableData: [],
      optionsArea: [],
      bodyindustryStr: "",
      query: {
        areaCode: "",
        bodyindustry: [],
        bodyindustryremarks: [],
        chiefInspector: [],
        identify: "",
        isPage: 0,
        isPeople: "",
        newlicenseno: "",
        page: 1,
        pageSize: 10,
        unitname: "",
        longitude: "1",
        regorgan: sessionStorage.getItem("unitName")||'',
      },
      sendData: {
        id: "",
        labelName: "",
        newLicenseNo: "",
        remark: "",
        unitName: "",
        updateName: sessionStorage.getItem("logname"),
        updateDepartment: sessionStorage.getItem("unitName"),
        identify: "",
      },
      total: 0,
      bodyindustryList: [],
    };
  },
  // 方法
  methods: {
  
    findAreaListNoParentByParentCode() {
      groupArea({
        params: {
          areaCode: this.query.areaCode,
        },
      }).then((res) => {
        this.optionsArea = [res.data];
      });
    },

    getList(e) {
      findSuperViseUnitDealtList(this.query).then((res) => {
        this.tableData = res.data.list;
        this.total = res.data.total;
      });
    },
    onCascaderChange(e) {
      if (!e.length) {
        this.query.bodyindustry = [];
        this.query.bodyindustryremarks = [];
      } else {
        this.query.bodyindustryremarks = this.$_.difference(this.$_.flattenDeep(e), [
          "食品生产经营者",
          "餐饮服务经营者",
          "食品流通经营者",
          "单位食堂",
          "食品销售经营者",
        ]);
        this.query.bodyindustry = this.$_.intersection(this.$_.flattenDeep(e), [
          "食品生产经营者",
          "餐饮服务经营者",
          "单位食堂",
          "食品流通经营者",
          "食品销售经营者",
        ]);
        if (
          this.$_.intersection(this.query.bodyindustryremarks, [
            "集体用餐配送或中央厨房",
            "特大型餐饮",
            "大型餐饮",
            "中型餐饮",
            "小型餐饮",
            "微型餐饮",
            "其他餐饮",
          ]).length
        ) {
          this.query.bodyindustry = this.$_.pull(
            this.query.bodyindustry,
            "餐饮服务经营者"
          );
        }
        if (
          this.$_.intersection(this.query.bodyindustryremarks, [
            "幼托机构食堂",
            "学校食堂",
            "养老机构食堂",
            "工地食堂",
            "机关企事业单位食堂",
            "其他食堂",
          ]).length
        ) {
          this.query.bodyindustry = this.$_.pull(this.query.bodyindustry, "单位食堂");
        }

        if (
          this.$_.intersection(this.query.bodyindustryremarks, [
            "食品批发销售商",
            "商场超市",
            "食杂店",
          ]).length
        ) {
          this.query.bodyindustry = this.$_.pull(
            this.query.bodyindustry,
            "食品销售经营者"
          );
        }
      }
    },
    CascaderArea(e) {
      this.query.areaCode = e[e.length - 1];
    },

    getPilotExport() {
      exportSuperViseUnitDeal({
        ...this.query,
        bodyindustryremarks: this.query.bodyindustryremarks.join(","),
        bodyindustry: this.query.bodyindustry.join(","),
        chiefInspector: this.query.chiefInspector.join(","),
      }).then((res) => {
        var blob = new Blob([res], {
          type: "application/vnd.ms-excel;charset=utf-8",
        });
        var downloadElement = document.createElement("a");
        var href = window.URL.createObjectURL(blob); //创建下载的链接
        console.log(href);
        downloadElement.href = href;
        downloadElement.download = "企业档案表" + new Date().getTime() + ".xlsx"; //下载后文件名
        document.body.appendChild(downloadElement);
        downloadElement.click(); //点击下载
        document.body.removeChild(downloadElement); //下载完成移除元素
        window.URL.revokeObjectURL(href); //释放掉blob对象
      });
    },
    onconfirm() {
      if (this.sendData.remark == "") return this.$error("请选择总监单位类别");

      if (
        this.sendData.remark == "其他企业(无需设置总监)" ||
        this.sendData.remark == "其他企业(无需设置总监)(仅限市平台单位)"
      ) {
        this.sendData.labelName = "特殊总监企业";
      } else {
        this.sendData.labelName = "总监企业";
      }
      saveDealtSuperViseUnitLabel(this.sendData).then((res) => {
        this.dialogVisibleLabel = false;
        this.$success(res.msg);
        this.getList();
      });
    },

    open(e) {
      this.sendData.unitName = e.operatorName || e.unitName;
      this.sendData.id = e.id;
      this.sendData.remark = e.remark;
      this.sendData.bodyIndustry = e.bodyIndustry;
      this.sendData.bodyIndustryRemarks = e.bodyIndustryRemarks;
      this.sendData.newLicenseNo = e.newLicenseNo;
      this.sendData.identify = e.identify;

      this.dialogVisibleLabel = true;
    },
  },
  // 监听属性
  watch: {},
  // 组件
  components: {
    inspect: () => import("@/views/enterprise/components/inspect"),
  },
  // 计算属性
  computed: {},
};
</script>

<style lang="less" scoped>
.right {
  text-align: right;
}
.el-button {
  margin-left: 20px;
}
.el-dropdown-menu {
  height: 600px;
  overflow: auto;
}
</style>
